package com.dhy;

import com.dhy.command.Command;
import com.dhy.command.StandardCommand;
import com.dhy.socket.RedisClientSocket;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author 大忽悠
 * @create 2022/5/29 20:08
 */
@Slf4j
public class RedisClientMain {
    private static Scanner scanner = new Scanner(System.in);
    private static final String KILL_SIGNAL="q";
    public static void main(String[] args) {
        RedisClientSocket socket = new RedisClientSocket();
        try {
            Socket client = socket.connect();
            StandardCommand command=new StandardCommand(client,socket.getConfig());
            System.out.println("请输入命令,按q结束输入:");

            String line = scanner.nextLine();

            while(!line.equals(KILL_SIGNAL)){
                //解析输入的命令
                Object execute = command.execute(line);
                System.out.println("命令执行结果为: "+execute);
                line=scanner.nextLine();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
